import { RollbackOutlined } from '@ant-design/icons';

import { Button } from 'antd';

import { FC, useEffect, useState } from 'react';

import { history } from 'umi';

interface GoBackButtonProps {
  link: string;
}

const GoBackButton: FC<GoBackButtonProps> = ({ link }) => {
  const [loading, setLoading] = useState(false);

  const handleClick = () => {
    if (link) {
      setLoading(true);

      history.push(link);
    }
  };

  useEffect(() => {
    return () => {
      setLoading(false);
    };
  }, []);

  return (
    <Button
      loading={loading}
      className="reset-btn"
      icon={<RollbackOutlined />}
      onClick={handleClick}
    >
      返回
    </Button>
  );
};

export default GoBackButton;
